<template>
	<view class="flex-col page">
		<view class="flex-col group">
			<view class="flex-col">
				<view class="flex-col section_1 view_3" v-for="(item, index) in columnList">
					<view class="flex-row group_2">
						<text class="text_1">材料名称</text>
						<input type="text" class="text_3" v-model="item.materialName" placeholder="请输入材料名称">
					</view>
					<image @click="del(index)"
						src="https://codefun-proj-user-res-1256085488.cos.ap-guangzhou.myqcloud.com/617a2ca7e4f1450011362b37/62b127f6d029820011531bae/16557827422757014750.png"
						class="image_4" />
					<view class="flex-col items-start group_3">
						<text class="text_5">材料清单图片</text>
						<shop-upload class="u-m-t-20" :maxCount="9" :fileList="item.materialPictures"
							@success="success($event,index)" @del="delectPic($event,index)"></shop-upload>
					</view>
				</view>

				<view class="flex-col items-center button" @click="adds"><text class="text_10">+ 添加材料</text></view>
			</view>
			<view class="flex-col items-center button_1" @click="submits"><text class="text_11">保存</text></view>
		</view>


	</view>
</template>

<script>
	export default {
		components: {},
		data() {
			return {
				columnList: [{
					materialName: '',
					materialPictures: [],
				}],
				fileList: [],
				infos: [],
				isDisplay: 1
			};
		},
		onLoad(option) {
			if (option.status) {
				this.isDisplay = option.status
			}
		},
		onShow() {
			if (uni.getStorageSync('materiallist').length > 0) {
				this.columnList = uni.getStorageSync('materiallist')
			}
		},
		methods: {
			success(e, index) {
				this.columnList[index].materialPictures.push(e);
				// this.fileList.push(file);
			},
			adds() {
				this.columnList.push({
					materialName: '',
					materialPictures: [],
				})
			},
			del(index) {
				this.columnList.splice(index, 1)
			},
			delectPic(e, index) {
				console.log(e);
				this.columnList[index].materialPictures.splice(e.index, 1);
			},
			submits() {
				if (this.columnList.length > 0) {
					this.columnList.map(item => {
						if (!item.materialName) {
							this.$u.toast('请将材料名称填写完整');
							return;
						}
						if (!item.materialPictures.length) {
							this.$u.toast('请将每项清单图片添加完整');
							return;
						}
					});
					uni.setStorage({
						key: 'materiallist',
						data: this.columnList,
						success: function() {
							uni.navigateBack({
								delta: 1
							})
						}
					})
				}
			}
		},
	};
</script>

<style scoped lang="scss">
	.section_1 {
		padding: 0 12px;
		background-color: #ffffff;
		border-radius: 8px;
		position: relative;
	}

	.group_2 {
		padding: 15px 0 20.5px;
		border-bottom: solid 0.5px #eeeeee;
	}

	.group_3 {
		padding: 15.5px 0 16px;
		position: relative;
	}

	.text_1 {
		color: #333333;
		font-size: 14px;
		font-family: '.AppleSystemUIFont';
		line-height: 16.5px;
	}

	.text_5 {
		color: #333333;
		font-size: 14px;
		font-family: '.AppleSystemUIFont';
		line-height: 16.5px;
	}

	.text_3 {
		margin-left: 19.5px;

		font-size: 14px;
		font-family: '.AppleSystemUIFont';
		line-height: 16.5px;
	}

	.image_2 {
		margin-top: 16.5px;
	}

	.page {
		background-color: #f6f7f9ff;
		width: 100%;
		overflow-y: auto;
		overflow-x: hidden;
		height: 100vh;
	}

	.group {
		padding: 12.5px 12px 32px;
		flex: 1 1 auto;
		overflow-y: auto;
	}

	.button_1 {
		margin: 67.5px 4px 0;
		// padding: 9.5px 0 15.5px;
		height: 88rpx;
		align-items: center;
		background-color: #1d6aff;
		border-radius: 22px;
	}

	.view_3 {
		margin-top: 10px;
	}

	.button {
		margin-top: 16px;
		padding: 6.5px 11.5px;
		align-self: flex-end;
		border-radius: 22px;
		background-image: url('https://codefun-proj-user-res-1256085488.cos.ap-guangzhou.myqcloud.com/617a2ca7e4f1450011362b37/62b127f6d029820011531bae/16557826986389174400.png');
		background-position: 0% 0%;
		background-size: 100% 100%;
		background-repeat: no-repeat;
		width: 100px;
	}

	.text_11 {
		height: 100%;
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: center;
		color: #ffffff;
		font-size: 16px;
		font-family: '.AppleSystemUIFont';

	}

	.image_1 {
		border-radius: 0px 8px 0px 8px;
		width: 24px;
		height: 20px;
		position: absolute;
		right: 0;
		top: 0;
	}

	.image_4 {
		width: 24px;
		height: 20px;
		position: absolute;
		right: 0;
		top: 0;
	}

	.text_10 {
		color: #1d6aff;
		font-size: 12px;
		font-family: '.AppleSystemUIFont';
		line-height: 14px;
	}

	.image_3 {
		width: 78px;
		height: 78px;
	}

	.image_5 {
		border-radius: 8px;
		width: 78px;
		height: 78px;
	}
</style>
